﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using TestesFixacao.Dominio.Modelos;

namespace TestesFixacao.Dominio.Writers
{
    public class DisciplinaWriter : IConvertible<Disciplina[]>
    {
        private QuestaoWriter _questaoWriter;

        public DisciplinaWriter(QuestaoWriter questaoWriter)
        {
            if (questaoWriter == null)
                throw new ArgumentNullException("questaoWriter");

            _questaoWriter = questaoWriter;
        }

        public void Convert(XmlTextWriter writer, Disciplina[] disciplinas)
        {
            writer.WriteStartElement("disciplinas");

            foreach (var item in disciplinas)
            {
                writer.WriteStartElement("serie");
                
                writer.WriteElementString("nome", item.Nome);

                _questaoWriter.Convert(writer, item.Questoes);

                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
    }
}
